package eurekaconsumer.eurekaconsumer;

import brave.sampler.Sampler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.logging.Level;
import java.util.logging.Logger;

@Controller
@Configuration
public class ConsumerController {
	private static final Logger LOG = Logger.getLogger(ConsumerController.class.getName());

	@Autowired
	HelloService helloService;
	@Bean
	@LoadBalanced
	public RestTemplate getRestTemplate(){
		return new RestTemplate();
	}

	@GetMapping("/info")
	@ResponseBody
	public String info(@RequestParam(value = "name", defaultValue = "forezp" )String name){
		LOG.log(Level.INFO, "calling trace eureka-consumer ");
		return "i'm service-hi========" +name;
	}

	@Bean
	public Sampler defaultSampler() {
		return Sampler.ALWAYS_SAMPLE;
	}

	@GetMapping(value = "/hi")
	@ResponseBody
	public String router(@RequestParam(value = "name",defaultValue = "libo") String name ){
		return helloService.hiService(name);
	}

}